﻿using Newtonsoft.Json;
using System;
/// <summary>
/// xwd：2012-10-12
/// </summary>
namespace WeChat.Core.Common
{
    /// <summary>
    /// 微信基本的响应结构
    /// </summary>
    public class WeChatBasicRs
    {
        /// <summary>
        /// 结果码
        /// </summary>
        [JsonProperty(PropertyName = "errcode")]
        public int ErrCode { get; set; }

        /// <summary>
        /// 结果文本说明
        /// </summary>
        [JsonProperty(PropertyName = "errmsg")]
        public string ErrMsg { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess
        {
            get { return ErrCode == 0; }
        }

        public static WeChatBasicRs GetSuccess(string msg = null)
        {
            return new WeChatBasicRs { ErrCode = 0, ErrMsg = msg ?? "完成" };
        }

        public static WeChatBasicRs GetFailed(string msg, Exception ex = null)
        {
            return new WeChatBasicRs
            {
                ErrCode = -1,
                ErrMsg = string.Format("{0}\n{1}", msg, ex != null ? "发生异常：" + ex.Message : string.Empty)
            };
        }
    }
}
